package com.woniuxy.article.controller;

import com.hc.PageBean.PageBean;
import com.hc.PageBean.vo.PaperVo;
import com.hc.entity.Comment;
import com.hc.entity.Paper;
import com.hc.entity.Shop;
import com.hc.utils.ResponseEntity;
import com.hc.vo.AgreeVo;
import com.woniuxy.article.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *@ClassName articleController
 *@Description
 *@Author TJ
 *@Date 2022/10/19 15:27
 *@Version 1.0
 **/
@RestController
@RequestMapping("/article")
public class articleController {
    @Autowired
    ArticleService articleService;
   //根据用户输入的字段，模糊查询文章，对比文章点赞数量和评论数，结合地图距离，返回商家信息
    @RequestMapping("/GetHotShop")
    public ResponseEntity<List<Shop>> GetHotShop(String message){
        List<Shop> shops = articleService.getByMessage(message);
        return new ResponseEntity<>("200","ok",shops);
   }
   //分页查询
//    @RequestMapping("/getByPages/{pageSize}/{pageNum}")
    @RequestMapping("/getByPages")
    public ResponseEntity selectByPage(@RequestBody PaperVo paperVo){
        ResponseEntity responseEntity =new ResponseEntity();
        try {
            responseEntity = new ResponseEntity(articleService.selectByPage(paperVo.getPageSize(), paperVo.getPageNum()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return responseEntity;
    }
    //文章点赞操作：未赞增加 已赞取消
    @RequestMapping("/agree")
    public ResponseEntity agree(@RequestBody AgreeVo agreeVo){
        //获取用户id和文章id
        boolean b = articleService.addAgree(agreeVo);
        return new ResponseEntity("200","ok",b);
    }

    //根据文章id获取文章内容
    @RequestMapping("/getPaperById")
    public ResponseEntity getPaperByPaperId(int id){
        //获取用户id和文章id
        Paper paper= articleService.getPaperByPaperId(id);
        return new ResponseEntity("200","ok",paper);
    }


}
 